package com.ecloud.gardensterminal.controller;

import com.ecloud.gardensterminal.common.JsonResult;
import com.ecloud.gardensterminal.controller.dto.GardensDeviceAreaDto;
import com.ecloud.gardensterminal.controller.dto.GardensDeviceDto;
import com.ecloud.gardensterminal.controller.vo.GardensDeviceAreaStatusVo;
import com.ecloud.gardensterminal.controller.vo.GardensDeviceAreaVo;
import com.ecloud.gardensterminal.controller.vo.GardensDeviceParallelingInfoVo;
import com.ecloud.gardensterminal.controller.vo.GardensDeviceSwitchInfoVo;
import com.ecloud.gardensterminal.domain.GardensDevice;
import com.ecloud.gardensterminal.server.GardensDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Squbi
 */
@RestController
public class GardensDeviceController {

    @Autowired
    private GardensDeviceService deviceService;

    @PostMapping("/device")
    public JsonResult selectByDto(@RequestBody GardensDeviceDto dto) {
        List<GardensDevice> result = deviceService.selectAll(dto);
        return JsonResult.success(result);
    }

    @PostMapping("/device/area")
    public JsonResult selectJoinArea(@RequestBody GardensDeviceAreaDto dto) {
        List<GardensDeviceAreaVo> result = deviceService.selectJoinArea(dto);
        return JsonResult.success(result);
    }

    @PostMapping("/device/area/status")
    public JsonResult selectJoinAreaStatus(@RequestBody GardensDeviceAreaDto dto) {
        List<GardensDeviceAreaStatusVo> result = deviceService.selectJoinAreaStatus(dto);
        return JsonResult.success(result);
    }

    @GetMapping("/device/switch")
    public JsonResult selectAllJoinSwitch(Integer deviceId) {
        List<GardensDeviceSwitchInfoVo> result = deviceService.selectJoinSwitch(deviceId);
        return JsonResult.success(result);
    }

    @GetMapping("/device/paralleling")
    public JsonResult selectAllJoinParalleling(Integer deviceId) {
        List<GardensDeviceParallelingInfoVo> result = deviceService.selectJoinParalleling(deviceId);
        return JsonResult.success(result);
    }

}